{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Implementation of Gradient Descent Algorithm from scratch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Importing all the required libraries\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import pylab\n",
    "import seaborn as sns\n",
    "import numpy as np\n",
    "import random\n",
    "from scipy import stats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "J= [32.07273388]\n",
      "J= [6.73719046]\n",
      "J= [5.93159357]\n",
      "J= [5.90115471]\n",
      "J= [5.89522859]\n",
      "J= [5.89009494]\n",
      "J= [5.88500416]\n",
      "J= [5.87993248]\n",
      "J= [5.87487909]\n",
      "J= [5.86984391]\n",
      "J= [5.86482687]\n",
      "J= [5.85982789]\n",
      "J= [5.85484692]\n",
      "J= [5.84988389]\n",
      "J= [5.84493874]\n",
      "J= [5.8400114]\n",
      "J= [5.83510181]\n",
      "J= [5.8302099]\n",
      "J= [5.82533562]\n",
      "J= [5.82047889]\n",
      "J= [5.81563965]\n",
      "J= [5.81081784]\n",
      "J= [5.8060134]\n",
      "J= [5.80122627]\n",
      "J= [5.79645638]\n",
      "J= [5.79170367]\n",
      "J= [5.78696808]\n",
      "J= [5.78224955]\n",
      "J= [5.77754801]\n",
      "J= [5.77286341]\n",
      "J= [5.76819568]\n",
      "J= [5.76354477]\n",
      "J= [5.75891061]\n",
      "J= [5.75429313]\n",
      "J= [5.7496923]\n",
      "J= [5.74510803]\n",
      "J= [5.74054027]\n",
      "J= [5.73598897]\n",
      "J= [5.73145406]\n",
      "J= [5.72693549]\n",
      "J= [5.72243319]\n",
      "J= [5.71794711]\n",
      "J= [5.71347718]\n",
      "J= [5.70902336]\n",
      "J= [5.70458558]\n",
      "J= [5.70016379]\n",
      "J= [5.69575792]\n",
      "J= [5.69136792]\n",
      "J= [5.68699373]\n",
      "J= [5.6826353]\n",
      "J= [5.67829257]\n",
      "J= [5.67396548]\n",
      "J= [5.66965398]\n",
      "J= [5.665358]\n",
      "J= [5.6610775]\n",
      "J= [5.65681242]\n",
      "J= [5.6525627]\n",
      "J= [5.64832829]\n",
      "J= [5.64410913]\n",
      "J= [5.63990517]\n",
      "J= [5.63571635]\n",
      "J= [5.63154261]\n",
      "J= [5.62738391]\n",
      "J= [5.6232402]\n",
      "J= [5.6191114]\n",
      "J= [5.61499748]\n",
      "J= [5.61089837]\n",
      "J= [5.60681403]\n",
      "J= [5.60274441]\n",
      "J= [5.59868944]\n",
      "J= [5.59464907]\n",
      "J= [5.59062326]\n",
      "J= [5.58661195]\n",
      "J= [5.58261509]\n",
      "J= [5.57863263]\n",
      "J= [5.57466451]\n",
      "J= [5.57071068]\n",
      "J= [5.56677109]\n",
      "J= [5.5628457]\n",
      "J= [5.55893444]\n",
      "J= [5.55503727]\n",
      "J= [5.55115414]\n",
      "J= [5.547285]\n",
      "J= [5.54342979]\n",
      "J= [5.53958847]\n",
      "J= [5.53576098]\n",
      "J= [5.53194728]\n",
      "J= [5.52814732]\n",
      "J= [5.52436105]\n",
      "J= [5.52058841]\n",
      "J= [5.51682936]\n",
      "J= [5.51308385]\n",
      "J= [5.50935183]\n",
      "J= [5.50563326]\n",
      "J= [5.50192808]\n",
      "J= [5.49823624]\n",
      "J= [5.49455771]\n",
      "J= [5.49089242]\n",
      "J= [5.48724033]\n",
      "J= [5.4836014]\n",
      "J= [5.47997558]\n",
      "J= [5.47636282]\n",
      "J= [5.47276307]\n",
      "J= [5.46917628]\n",
      "J= [5.46560242]\n",
      "J= [5.46204143]\n",
      "J= [5.45849326]\n",
      "J= [5.45495788]\n",
      "J= [5.45143522]\n",
      "J= [5.44792526]\n",
      "J= [5.44442794]\n",
      "J= [5.44094322]\n",
      "J= [5.43747105]\n",
      "J= [5.43401138]\n",
      "J= [5.43056418]\n",
      "J= [5.42712939]\n",
      "J= [5.42370698]\n",
      "J= [5.42029689]\n",
      "J= [5.41689909]\n",
      "J= [5.41351352]\n",
      "J= [5.41014015]\n",
      "J= [5.40677893]\n",
      "J= [5.40342982]\n",
      "J= [5.40009277]\n",
      "J= [5.39676774]\n",
      "J= [5.39345469]\n",
      "J= [5.39015357]\n",
      "J= [5.38686434]\n",
      "J= [5.38358696]\n",
      "J= [5.38032138]\n",
      "J= [5.37706756]\n",
      "J= [5.37382547]\n",
      "J= [5.37059505]\n",
      "J= [5.36737627]\n",
      "J= [5.36416908]\n",
      "J= [5.36097345]\n",
      "J= [5.35778933]\n",
      "J= [5.35461667]\n",
      "J= [5.35145544]\n",
      "J= [5.3483056]\n",
      "J= [5.34516711]\n",
      "J= [5.34203991]\n",
      "J= [5.33892399]\n",
      "J= [5.33581928]\n",
      "J= [5.33272576]\n",
      "J= [5.32964339]\n",
      "J= [5.32657211]\n",
      "J= [5.3235119]\n",
      "J= [5.32046271]\n",
      "J= [5.3174245]\n",
      "J= [5.31439724]\n",
      "J= [5.31138088]\n",
      "J= [5.30837538]\n",
      "J= [5.30538071]\n",
      "J= [5.30239683]\n",
      "J= [5.2994237]\n",
      "J= [5.29646127]\n",
      "J= [5.29350951]\n",
      "J= [5.29056839]\n",
      "J= [5.28763786]\n",
      "J= [5.28471789]\n",
      "J= [5.28180843]\n",
      "J= [5.27890945]\n",
      "J= [5.27602092]\n",
      "J= [5.27314279]\n",
      "J= [5.27027503]\n",
      "J= [5.26741759]\n",
      "J= [5.26457045]\n",
      "J= [5.26173356]\n",
      "J= [5.2589069]\n",
      "J= [5.25609041]\n",
      "J= [5.25328407]\n",
      "J= [5.25048783]\n",
      "J= [5.24770167]\n",
      "J= [5.24492555]\n",
      "J= [5.24215942]\n",
      "J= [5.23940326]\n",
      "J= [5.23665702]\n",
      "J= [5.23392068]\n",
      "J= [5.23119419]\n",
      "J= [5.22847752]\n",
      "J= [5.22577064]\n",
      "J= [5.22307351]\n",
      "J= [5.22038609]\n",
      "J= [5.21770835]\n",
      "J= [5.21504026]\n",
      "J= [5.21238178]\n",
      "J= [5.20973288]\n",
      "J= [5.20709351]\n",
      "J= [5.20446365]\n",
      "J= [5.20184327]\n",
      "J= [5.19923232]\n",
      "J= [5.19663078]\n",
      "J= [5.19403861]\n",
      "J= [5.19145577]\n",
      "J= [5.18888224]\n",
      "J= [5.18631798]\n",
      "J= [5.18376295]\n",
      "J= [5.18121713]\n",
      "J= [5.17868048]\n",
      "J= [5.17615296]\n",
      "J= [5.17363455]\n",
      "J= [5.17112521]\n",
      "J= [5.16862491]\n",
      "J= [5.16613361]\n",
      "J= [5.16365129]\n",
      "J= [5.16117791]\n",
      "J= [5.15871344]\n",
      "J= [5.15625784]\n",
      "J= [5.15381109]\n",
      "J= [5.15137315]\n",
      "J= [5.148944]\n",
      "J= [5.14652359]\n",
      "J= [5.1441119]\n",
      "J= [5.1417089]\n",
      "J= [5.13931455]\n",
      "J= [5.13692883]\n",
      "J= [5.1345517]\n",
      "J= [5.13218314]\n",
      "J= [5.1298231]\n",
      "J= [5.12747157]\n",
      "J= [5.1251285]\n",
      "J= [5.12279388]\n",
      "J= [5.12046766]\n",
      "J= [5.11814983]\n",
      "J= [5.11584034]\n",
      "J= [5.11353917]\n",
      "J= [5.11124629]\n",
      "J= [5.10896167]\n",
      "J= [5.10668527]\n",
      "J= [5.10441708]\n",
      "J= [5.10215706]\n",
      "J= [5.09990518]\n",
      "J= [5.0976614]\n",
      "J= [5.09542571]\n",
      "J= [5.09319808]\n",
      "J= [5.09097846]\n",
      "J= [5.08876685]\n",
      "J= [5.08656319]\n",
      "J= [5.08436748]\n",
      "J= [5.08217967]\n",
      "J= [5.07999975]\n",
      "J= [5.07782768]\n",
      "J= [5.07566343]\n",
      "J= [5.07350697]\n",
      "J= [5.07135828]\n",
      "J= [5.06921734]\n",
      "J= [5.0670841]\n",
      "J= [5.06495855]\n",
      "J= [5.06284065]\n",
      "J= [5.06073039]\n",
      "J= [5.05862772]\n",
      "J= [5.05653263]\n",
      "J= [5.05444508]\n",
      "J= [5.05236505]\n",
      "J= [5.05029252]\n",
      "J= [5.04822745]\n",
      "J= [5.04616982]\n",
      "J= [5.0441196]\n",
      "J= [5.04207676]\n",
      "J= [5.04004129]\n",
      "J= [5.03801314]\n",
      "J= [5.0359923]\n",
      "J= [5.03397874]\n",
      "J= [5.03197243]\n",
      "J= [5.02997335]\n",
      "J= [5.02798147]\n",
      "J= [5.02599676]\n",
      "J= [5.0240192]\n",
      "J= [5.02204877]\n",
      "J= [5.02008543]\n",
      "J= [5.01812917]\n",
      "J= [5.01617995]\n",
      "J= [5.01423775]\n",
      "J= [5.01230255]\n",
      "J= [5.01037431]\n",
      "J= [5.00845303]\n",
      "J= [5.00653866]\n",
      "J= [5.00463119]\n",
      "J= [5.00273059]\n",
      "J= [5.00083684]\n",
      "J= [4.9989499]\n",
      "J= [4.99706977]\n",
      "J= [4.9951964]\n",
      "J= [4.99332979]\n",
      "J= [4.99146989]\n",
      "J= [4.9896167]\n",
      "J= [4.98777018]\n",
      "J= [4.98593031]\n",
      "J= [4.98409707]\n",
      "J= [4.98227043]\n",
      "J= [4.98045038]\n",
      "J= [4.97863687]\n",
      "J= [4.9768299]\n",
      "J= [4.97502944]\n",
      "J= [4.97323547]\n",
      "J= [4.97144795]\n",
      "J= [4.96966687]\n",
      "J= [4.96789221]\n",
      "J= [4.96612395]\n",
      "J= [4.96436205]\n",
      "J= [4.96260649]\n",
      "J= [4.96085726]\n",
      "J= [4.95911433]\n",
      "J= [4.95737768]\n",
      "J= [4.95564729]\n",
      "J= [4.95392312]\n",
      "J= [4.95220517]\n",
      "J= [4.95049341]\n",
      "J= [4.94878781]\n",
      "J= [4.94708835]\n",
      "J= [4.94539502]\n",
      "J= [4.94370778]\n",
      "J= [4.94202663]\n",
      "J= [4.94035152]\n",
      "J= [4.93868246]\n",
      "J= [4.9370194]\n",
      "J= [4.93536233]\n",
      "J= [4.93371123]\n",
      "J= [4.93206608]\n",
      "J= [4.93042686]\n",
      "J= [4.92879354]\n",
      "J= [4.9271661]\n",
      "J= [4.92554453]\n",
      "J= [4.92392879]\n",
      "J= [4.92231888]\n",
      "J= [4.92071476]\n",
      "J= [4.91911642]\n",
      "J= [4.91752384]\n",
      "J= [4.915937]\n",
      "J= [4.91435587]\n",
      "J= [4.91278043]\n",
      "J= [4.91121067]\n",
      "J= [4.90964657]\n",
      "J= [4.9080881]\n",
      "J= [4.90653524]\n",
      "J= [4.90498798]\n",
      "J= [4.90344629]\n",
      "J= [4.90191015]\n",
      "J= [4.90037954]\n",
      "J= [4.89885445]\n",
      "J= [4.89733485]\n",
      "J= [4.89582073]\n",
      "J= [4.89431206]\n",
      "J= [4.89280882]\n",
      "J= [4.891311]\n",
      "J= [4.88981857]\n",
      "J= [4.88833152]\n",
      "J= [4.88684982]\n",
      "J= [4.88537346]\n",
      "J= [4.88390242]\n",
      "J= [4.88243668]\n",
      "J= [4.88097622]\n",
      "J= [4.87952102]\n",
      "J= [4.87807106]\n",
      "J= [4.87662632]\n",
      "J= [4.87518678]\n",
      "J= [4.87375243]\n",
      "J= [4.87232325]\n",
      "J= [4.87089922]\n",
      "J= [4.86948031]\n",
      "J= [4.86806652]\n",
      "J= [4.86665782]\n",
      "J= [4.86525419]\n",
      "J= [4.86385562]\n",
      "J= [4.86246208]\n",
      "J= [4.86107357]\n",
      "J= [4.85969005]\n",
      "J= [4.85831152]\n",
      "J= [4.85693796]\n",
      "J= [4.85556934]\n",
      "J= [4.85420565]\n",
      "J= [4.85284687]\n",
      "J= [4.85149299]\n",
      "J= [4.85014399]\n",
      "J= [4.84879984]\n",
      "J= [4.84746054]\n",
      "J= [4.84612606]\n",
      "J= [4.84479638]\n",
      "J= [4.8434715]\n",
      "J= [4.84215138]\n",
      "J= [4.84083603]\n",
      "J= [4.83952541]\n",
      "J= [4.83821951]\n",
      "J= [4.83691831]\n",
      "J= [4.83562181]\n",
      "J= [4.83432997]\n",
      "J= [4.83304278]\n",
      "J= [4.83176023]\n",
      "J= [4.83048231]\n",
      "J= [4.82920898]\n",
      "J= [4.82794024]\n",
      "J= [4.82667607]\n",
      "J= [4.82541645]\n",
      "J= [4.82416138]\n",
      "J= [4.82291082]\n",
      "J= [4.82166476]\n",
      "J= [4.8204232]\n",
      "J= [4.8191861]\n",
      "J= [4.81795347]\n",
      "J= [4.81672527]\n",
      "J= [4.81550149]\n",
      "J= [4.81428213]\n",
      "J= [4.81306715]\n",
      "J= [4.81185656]\n",
      "J= [4.81065032]\n",
      "J= [4.80944843]\n",
      "J= [4.80825086]\n",
      "J= [4.80705761]\n",
      "J= [4.80586866]\n",
      "J= [4.80468399]\n",
      "J= [4.80350359]\n",
      "J= [4.80232744]\n",
      "J= [4.80115553]\n",
      "J= [4.79998784]\n",
      "J= [4.79882435]\n",
      "J= [4.79766505]\n",
      "J= [4.79650993]\n",
      "J= [4.79535897]\n",
      "J= [4.79421216]\n",
      "J= [4.79306948]\n",
      "J= [4.79193091]\n",
      "J= [4.79079644]\n",
      "J= [4.78966606]\n",
      "J= [4.78853976]\n",
      "J= [4.7874175]\n",
      "J= [4.7862993]\n",
      "J= [4.78518511]\n",
      "J= [4.78407495]\n",
      "J= [4.78296878]\n",
      "J= [4.78186659]\n",
      "J= [4.78076838]\n",
      "J= [4.77967412]\n",
      "J= [4.7785838]\n",
      "J= [4.77749741]\n",
      "J= [4.77641493]\n",
      "J= [4.77533635]\n",
      "J= [4.77426166]\n",
      "J= [4.77319084]\n",
      "J= [4.77212387]\n",
      "J= [4.77106075]\n",
      "J= [4.77000146]\n",
      "J= [4.76894598]\n",
      "J= [4.7678943]\n",
      "J= [4.76684642]\n",
      "J= [4.7658023]\n",
      "J= [4.76476195]\n",
      "J= [4.76372535]\n",
      "J= [4.76269247]\n",
      "J= [4.76166332]\n",
      "J= [4.76063788]\n",
      "J= [4.75961613]\n",
      "J= [4.75859806]\n",
      "J= [4.75758366]\n",
      "J= [4.75657291]\n",
      "J= [4.7555658]\n",
      "J= [4.75456232]\n",
      "J= [4.75356245]\n",
      "J= [4.75256619]\n",
      "J= [4.75157351]\n",
      "J= [4.75058441]\n",
      "J= [4.74959887]\n",
      "J= [4.74861688]\n",
      "J= [4.74763843]\n",
      "J= [4.7466635]\n",
      "J= [4.74569209]\n",
      "J= [4.74472417]\n",
      "J= [4.74375974]\n",
      "J= [4.74279878]\n",
      "J= [4.74184129]\n",
      "J= [4.74088724]\n",
      "J= [4.73993663]\n",
      "J= [4.73898945]\n",
      "J= [4.73804567]\n",
      "J= [4.7371053]\n",
      "J= [4.73616831]\n",
      "J= [4.7352347]\n",
      "J= [4.73430445]\n",
      "J= [4.73337755]\n",
      "J= [4.73245399]\n",
      "J= [4.73153376]\n",
      "J= [4.73061684]\n",
      "J= [4.72970322]\n",
      "J= [4.7287929]\n",
      "J= [4.72788585]\n",
      "J= [4.72698207]\n",
      "J= [4.72608155]\n",
      "J= [4.72518427]\n",
      "J= [4.72429022]\n",
      "J= [4.72339939]\n",
      "J= [4.72251177]\n",
      "J= [4.72162735]\n",
      "J= [4.72074611]\n",
      "J= [4.71986805]\n",
      "J= [4.71899315]\n",
      "J= [4.7181214]\n",
      "J= [4.71725279]\n",
      "J= [4.71638731]\n",
      "J= [4.71552495]\n",
      "J= [4.71466569]\n",
      "J= [4.71380953]\n",
      "J= [4.71295645]\n",
      "J= [4.71210645]\n",
      "J= [4.71125951]\n",
      "J= [4.71041561]\n",
      "J= [4.70957476]\n",
      "J= [4.70873694]\n",
      "J= [4.70790213]\n",
      "J= [4.70707033]\n",
      "J= [4.70624153]\n",
      "J= [4.70541571]\n",
      "J= [4.70459287]\n",
      "J= [4.70377299]\n",
      "J= [4.70295606]\n",
      "J= [4.70214208]\n",
      "J= [4.70133103]\n",
      "J= [4.7005229]\n",
      "J= [4.69971768]\n",
      "J= [4.69891536]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "J= [4.69811593]\n",
      "J= [4.69731938]\n",
      "J= [4.6965257]\n",
      "J= [4.69573487]\n",
      "J= [4.6949469]\n",
      "J= [4.69416177]\n",
      "J= [4.69337946]\n",
      "J= [4.69259997]\n",
      "J= [4.69182329]\n",
      "J= [4.6910494]\n",
      "J= [4.69027831]\n",
      "J= [4.68950999]\n",
      "J= [4.68874444]\n",
      "J= [4.68798164]\n",
      "J= [4.68722159]\n",
      "J= [4.68646428]\n",
      "J= [4.6857097]\n",
      "J= [4.68495784]\n",
      "J= [4.68420868]\n",
      "J= [4.68346223]\n",
      "J= [4.68271846]\n",
      "J= [4.68197737]\n",
      "J= [4.68123895]\n",
      "J= [4.68050319]\n",
      "J= [4.67977008]\n",
      "J= [4.67903961]\n",
      "J= [4.67831177]\n",
      "J= [4.67758656]\n",
      "J= [4.67686395]\n",
      "J= [4.67614395]\n",
      "J= [4.67542654]\n",
      "J= [4.67471172]\n",
      "J= [4.67399947]\n",
      "J= [4.67328979]\n",
      "J= [4.67258266]\n",
      "J= [4.67187808]\n",
      "J= [4.67117604]\n",
      "J= [4.67047652]\n",
      "J= [4.66977953]\n",
      "J= [4.66908504]\n",
      "J= [4.66839306]\n",
      "J= [4.66770357]\n",
      "J= [4.66701656]\n",
      "J= [4.66633203]\n",
      "J= [4.66564997]\n",
      "J= [4.66497036]\n",
      "J= [4.6642932]\n",
      "J= [4.66361847]\n",
      "J= [4.66294618]\n",
      "J= [4.66227631]\n",
      "J= [4.66160885]\n",
      "J= [4.6609438]\n",
      "J= [4.66028114]\n",
      "J= [4.65962087]\n",
      "J= [4.65896298]\n",
      "J= [4.65830745]\n",
      "J= [4.65765429]\n",
      "J= [4.65700348]\n",
      "J= [4.65635502]\n",
      "J= [4.65570889]\n",
      "J= [4.65506509]\n",
      "J= [4.6544236]\n",
      "J= [4.65378443]\n",
      "J= [4.65314756]\n",
      "J= [4.65251298]\n",
      "J= [4.65188069]\n",
      "J= [4.65125068]\n",
      "J= [4.65062293]\n",
      "J= [4.64999745]\n",
      "J= [4.64937422]\n",
      "J= [4.64875324]\n",
      "J= [4.64813449]\n",
      "J= [4.64751797]\n",
      "J= [4.64690367]\n",
      "J= [4.64629158]\n",
      "J= [4.6456817]\n",
      "J= [4.64507402]\n",
      "J= [4.64446852]\n",
      "J= [4.64386521]\n",
      "J= [4.64326406]\n",
      "J= [4.64266509]\n",
      "J= [4.64206827]\n",
      "J= [4.6414736]\n",
      "J= [4.64088107]\n",
      "J= [4.64029068]\n",
      "J= [4.63970241]\n",
      "J= [4.63911626]\n",
      "J= [4.63853223]\n",
      "J= [4.63795029]\n",
      "J= [4.63737046]\n",
      "J= [4.63679271]\n",
      "J= [4.63621704]\n",
      "J= [4.63564345]\n",
      "J= [4.63507192]\n",
      "J= [4.63450245]\n",
      "J= [4.63393503]\n",
      "J= [4.63336966]\n",
      "J= [4.63280632]\n",
      "J= [4.63224501]\n",
      "J= [4.63168573]\n",
      "J= [4.63112845]\n",
      "J= [4.63057319]\n",
      "J= [4.63001992]\n",
      "J= [4.62946865]\n",
      "J= [4.62891937]\n",
      "J= [4.62837206]\n",
      "J= [4.62782672]\n",
      "J= [4.62728335]\n",
      "J= [4.62674193]\n",
      "J= [4.62620247]\n",
      "J= [4.62566495]\n",
      "J= [4.62512936]\n",
      "J= [4.62459571]\n",
      "J= [4.62406397]\n",
      "J= [4.62353415]\n",
      "J= [4.62300624]\n",
      "J= [4.62248023]\n",
      "J= [4.62195612]\n",
      "J= [4.62143389]\n",
      "J= [4.62091355]\n",
      "J= [4.62039507]\n",
      "J= [4.61987847]\n",
      "J= [4.61936373]\n",
      "J= [4.61885084]\n",
      "J= [4.6183398]\n",
      "J= [4.6178306]\n",
      "J= [4.61732323]\n",
      "J= [4.61681769]\n",
      "J= [4.61631397]\n",
      "J= [4.61581207]\n",
      "J= [4.61531197]\n",
      "J= [4.61481368]\n",
      "J= [4.61431718]\n",
      "J= [4.61382246]\n",
      "J= [4.61332954]\n",
      "J= [4.61283838]\n",
      "J= [4.612349]\n",
      "J= [4.61186137]\n",
      "J= [4.61137551]\n",
      "J= [4.61089139]\n",
      "J= [4.61040902]\n",
      "J= [4.60992838]\n",
      "J= [4.60944948]\n",
      "J= [4.6089723]\n",
      "J= [4.60849684]\n",
      "J= [4.6080231]\n",
      "J= [4.60755106]\n",
      "J= [4.60708071]\n",
      "J= [4.60661207]\n",
      "J= [4.60614511]\n",
      "J= [4.60567983]\n",
      "J= [4.60521623]\n",
      "J= [4.6047543]\n",
      "J= [4.60429404]\n",
      "J= [4.60383543]\n",
      "J= [4.60337847]\n",
      "J= [4.60292316]\n",
      "J= [4.60246949]\n",
      "J= [4.60201745]\n",
      "J= [4.60156704]\n",
      "J= [4.60111826]\n",
      "J= [4.60067109]\n",
      "J= [4.60022553]\n",
      "J= [4.59978157]\n",
      "J= [4.59933922]\n",
      "J= [4.59889846]\n",
      "J= [4.59845928]\n",
      "J= [4.59802169]\n",
      "J= [4.59758567]\n",
      "J= [4.59715123]\n",
      "J= [4.59671835]\n",
      "J= [4.59628702]\n",
      "J= [4.59585726]\n",
      "J= [4.59542904]\n",
      "J= [4.59500236]\n",
      "J= [4.59457722]\n",
      "J= [4.59415361]\n",
      "J= [4.59373152]\n",
      "J= [4.59331096]\n",
      "J= [4.59289191]\n",
      "J= [4.59247437]\n",
      "J= [4.59205834]\n",
      "J= [4.5916438]\n",
      "J= [4.59123076]\n",
      "J= [4.5908192]\n",
      "J= [4.59040913]\n",
      "J= [4.59000053]\n",
      "J= [4.58959341]\n",
      "J= [4.58918775]\n",
      "J= [4.58878355]\n",
      "J= [4.58838081]\n",
      "J= [4.58797952]\n",
      "J= [4.58757968]\n",
      "J= [4.58718127]\n",
      "J= [4.5867843]\n",
      "J= [4.58638876]\n",
      "J= [4.58599465]\n",
      "J= [4.58560195]\n",
      "J= [4.58521067]\n",
      "J= [4.5848208]\n",
      "J= [4.58443233]\n",
      "J= [4.58404526]\n",
      "J= [4.58365959]\n",
      "J= [4.58327531]\n",
      "J= [4.5828924]\n",
      "J= [4.58251088]\n",
      "J= [4.58213074]\n",
      "J= [4.58175196]\n",
      "J= [4.58137454]\n",
      "J= [4.58099849]\n",
      "J= [4.58062379]\n",
      "J= [4.58025044]\n",
      "J= [4.57987844]\n",
      "J= [4.57950777]\n",
      "J= [4.57913844]\n",
      "J= [4.57877044]\n",
      "J= [4.57840377]\n",
      "J= [4.57803841]\n",
      "J= [4.57767437]\n",
      "J= [4.57731165]\n",
      "J= [4.57695023]\n",
      "J= [4.57659011]\n",
      "J= [4.57623129]\n",
      "J= [4.57587376]\n",
      "J= [4.57551752]\n",
      "J= [4.57516256]\n",
      "J= [4.57480888]\n",
      "J= [4.57445648]\n",
      "J= [4.57410534]\n",
      "J= [4.57375547]\n",
      "J= [4.57340686]\n",
      "J= [4.57305951]\n",
      "J= [4.5727134]\n",
      "J= [4.57236854]\n",
      "J= [4.57202493]\n",
      "J= [4.57168255]\n",
      "J= [4.57134141]\n",
      "J= [4.57100149]\n",
      "J= [4.5706628]\n",
      "J= [4.57032533]\n",
      "J= [4.56998908]\n",
      "J= [4.56965403]\n",
      "J= [4.56932019]\n",
      "J= [4.56898756]\n",
      "J= [4.56865612]\n",
      "J= [4.56832588]\n",
      "J= [4.56799682]\n",
      "J= [4.56766896]\n",
      "J= [4.56734227]\n",
      "J= [4.56701676]\n",
      "J= [4.56669242]\n",
      "J= [4.56636925]\n",
      "J= [4.56604724]\n",
      "J= [4.5657264]\n",
      "J= [4.56540671]\n",
      "J= [4.56508817]\n",
      "J= [4.56477078]\n",
      "J= [4.56445453]\n",
      "J= [4.56413942]\n",
      "J= [4.56382544]\n",
      "J= [4.5635126]\n",
      "J= [4.56320088]\n",
      "J= [4.56289029]\n",
      "J= [4.56258082]\n",
      "J= [4.56227246]\n",
      "J= [4.56196521]\n",
      "J= [4.56165906]\n",
      "J= [4.56135402]\n",
      "J= [4.56105008]\n",
      "J= [4.56074723]\n",
      "J= [4.56044548]\n",
      "J= [4.56014481]\n",
      "J= [4.55984522]\n",
      "J= [4.55954672]\n",
      "J= [4.55924929]\n",
      "J= [4.55895293]\n",
      "J= [4.55865763]\n",
      "J= [4.5583634]\n",
      "J= [4.55807023]\n",
      "J= [4.55777812]\n",
      "J= [4.55748706]\n",
      "J= [4.55719705]\n",
      "J= [4.55690808]\n",
      "J= [4.55662015]\n",
      "J= [4.55633326]\n",
      "J= [4.5560474]\n",
      "J= [4.55576258]\n",
      "J= [4.55547878]\n",
      "J= [4.555196]\n",
      "J= [4.55491424]\n",
      "J= [4.55463349]\n",
      "J= [4.55435376]\n",
      "J= [4.55407503]\n",
      "J= [4.55379731]\n",
      "J= [4.55352058]\n",
      "J= [4.55324486]\n",
      "J= [4.55297012]\n",
      "J= [4.55269638]\n",
      "J= [4.55242362]\n",
      "J= [4.55215185]\n",
      "J= [4.55188105]\n",
      "J= [4.55161123]\n",
      "J= [4.55134239]\n",
      "J= [4.55107451]\n",
      "J= [4.55080759]\n",
      "J= [4.55054164]\n",
      "J= [4.55027664]\n",
      "J= [4.5500126]\n",
      "J= [4.54974951]\n",
      "J= [4.54948737]\n",
      "J= [4.54922617]\n",
      "J= [4.54896591]\n",
      "J= [4.54870659]\n",
      "J= [4.5484482]\n",
      "J= [4.54819075]\n",
      "J= [4.54793422]\n",
      "J= [4.54767862]\n",
      "J= [4.54742393]\n",
      "J= [4.54717017]\n",
      "J= [4.54691731]\n",
      "J= [4.54666537]\n",
      "J= [4.54641434]\n",
      "J= [4.54616421]\n",
      "J= [4.54591498]\n",
      "J= [4.54566665]\n",
      "J= [4.54541921]\n",
      "J= [4.54517267]\n",
      "J= [4.54492701]\n",
      "J= [4.54468224]\n",
      "J= [4.54443835]\n",
      "J= [4.54419534]\n",
      "J= [4.5439532]\n",
      "J= [4.54371194]\n",
      "J= [4.54347154]\n",
      "J= [4.54323201]\n",
      "J= [4.54299334]\n",
      "J= [4.54275554]\n",
      "J= [4.54251859]\n",
      "J= [4.54228249]\n",
      "J= [4.54204724]\n",
      "J= [4.54181284]\n",
      "J= [4.54157929]\n",
      "J= [4.54134657]\n",
      "J= [4.5411147]\n",
      "J= [4.54088366]\n",
      "J= [4.54065345]\n",
      "J= [4.54042407]\n",
      "J= [4.54019552]\n",
      "J= [4.53996779]\n",
      "J= [4.53974088]\n",
      "J= [4.53951478]\n",
      "J= [4.53928951]\n",
      "J= [4.53906504]\n",
      "J= [4.53884138]\n",
      "J= [4.53861853]\n",
      "J= [4.53839648]\n",
      "J= [4.53817523]\n",
      "J= [4.53795478]\n",
      "J= [4.53773512]\n",
      "J= [4.53751625]\n",
      "J= [4.53729817]\n",
      "J= [4.53708088]\n",
      "J= [4.53686437]\n",
      "J= [4.53664864]\n",
      "J= [4.53643368]\n",
      "J= [4.5362195]\n",
      "J= [4.5360061]\n",
      "J= [4.53579346]\n",
      "J= [4.53558158]\n",
      "J= [4.53537047]\n",
      "J= [4.53516012]\n",
      "J= [4.53495053]\n",
      "J= [4.53474169]\n",
      "J= [4.53453361]\n",
      "J= [4.53432627]\n",
      "J= [4.53411968]\n",
      "J= [4.53391384]\n",
      "J= [4.53370873]\n",
      "J= [4.53350437]\n",
      "J= [4.53330074]\n",
      "J= [4.53309784]\n",
      "J= [4.53289568]\n",
      "J= [4.53269424]\n",
      "J= [4.53249353]\n",
      "J= [4.53229355]\n",
      "J= [4.53209428]\n",
      "J= [4.53189573]\n",
      "J= [4.53169789]\n",
      "J= [4.53150077]\n",
      "J= [4.53130436]\n",
      "J= [4.53110866]\n",
      "J= [4.53091366]\n",
      "J= [4.53071936]\n",
      "J= [4.53052576]\n",
      "J= [4.53033286]\n",
      "J= [4.53014066]\n",
      "J= [4.52994915]\n",
      "J= [4.52975832]\n",
      "J= [4.52956819]\n",
      "J= [4.52937874]\n",
      "J= [4.52918997]\n",
      "J= [4.52900188]\n",
      "J= [4.52881447]\n",
      "J= [4.52862773]\n",
      "J= [4.52844167]\n",
      "J= [4.52825628]\n",
      "J= [4.52807155]\n",
      "J= [4.52788749]\n",
      "J= [4.52770409]\n",
      "J= [4.52752136]\n",
      "J= [4.52733928]\n",
      "J= [4.52715786]\n",
      "J= [4.52697709]\n",
      "J= [4.52679697]\n",
      "J= [4.5266175]\n",
      "J= [4.52643868]\n",
      "J= [4.5262605]\n",
      "J= [4.52608297]\n",
      "J= [4.52590607]\n",
      "J= [4.52572981]\n",
      "J= [4.52555418]\n",
      "J= [4.52537919]\n",
      "J= [4.52520483]\n",
      "J= [4.52503109]\n",
      "J= [4.52485799]\n",
      "J= [4.5246855]\n",
      "J= [4.52451364]\n",
      "J= [4.52434239]\n",
      "J= [4.52417177]\n",
      "J= [4.52400175]\n",
      "J= [4.52383235]\n",
      "J= [4.52366356]\n",
      "J= [4.52349538]\n",
      "J= [4.5233278]\n",
      "J= [4.52316083]\n",
      "J= [4.52299446]\n",
      "J= [4.52282868]\n",
      "J= [4.52266351]\n",
      "J= [4.52249893]\n",
      "J= [4.52233494]\n",
      "J= [4.52217154]\n",
      "J= [4.52200874]\n",
      "J= [4.52184651]\n",
      "J= [4.52168488]\n",
      "J= [4.52152382]\n",
      "J= [4.52136335]\n",
      "J= [4.52120345]\n",
      "J= [4.52104413]\n",
      "J= [4.52088538]\n",
      "J= [4.5207272]\n",
      "J= [4.5205696]\n",
      "J= [4.52041256]\n",
      "J= [4.52025609]\n",
      "J= [4.52010018]\n",
      "J= [4.51994483]\n",
      "J= [4.51979004]\n",
      "J= [4.51963581]\n",
      "J= [4.51948214]\n",
      "J= [4.51932902]\n",
      "J= [4.51917645]\n",
      "J= [4.51902443]\n",
      "J= [4.51887295]\n",
      "J= [4.51872203]\n",
      "J= [4.51857164]\n",
      "J= [4.5184218]\n",
      "J= [4.5182725]\n",
      "J= [4.51812373]\n",
      "J= [4.51797551]\n",
      "J= [4.51782781]\n",
      "J= [4.51768065]\n",
      "J= [4.51753402]\n",
      "J= [4.51738791]\n",
      "J= [4.51724233]\n",
      "J= [4.51709728]\n",
      "J= [4.51695275]\n",
      "J= [4.51680874]\n",
      "J= [4.51666525]\n",
      "J= [4.51652227]\n",
      "J= [4.51637981]\n",
      "J= [4.51623786]\n",
      "J= [4.51609643]\n",
      "J= [4.5159555]\n",
      "Maximum iterations exceeded!\n",
      "theta0=[-3.24140214]theta1=[1.1272942]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAIABJREFUeJzt3X+QVOWZL/DvwzjogCQDMhIYxEFLICZGh0y5yiQaf45RF0atdeNuArUGcatW6+LlzgJryuXe7L2gJGy0KrVZFK/IEteoMBJ/XCRoghhxd3DAkcgsiqA0CIPDiMgg8+O5f3T30NN9Tvfp7vPjPae/nypqZt4+Peex5/j02+/7vO8RVQUREYXfkKADICIidzChExFFBBM6EVFEMKETEUUEEzoRUUQwoRMRRQQTOhFRRDChExFFBBM6EVFEnJbrABE5B8CTAL4GoB/AclV9WEQWAbgLQEfi0H9Q1Zey/a7Ro0drTU1NUQETEZWarVu3HlbVqlzH5UzoAHoBzFPVt0VkBICtIrIh8dg/q+rPnAZVU1ODlpYWp4cTEREAEdnr5LicCV1VDwA4kPj+cxF5D0B1ceEREZHb8hpDF5EaALUA3ko03SMi74jI4yIy0uXYiIgoD44TuoicCeA5AHNV9SiAfwFwPoBLEO/B/9zmeXNEpEVEWjo6OqwOISIiFzhK6CJSjngyX62qawBAVQ+qap+q9gN4FMClVs9V1eWqWqeqdVVVOcf0iYioQDkTuogIgBUA3lPVZSntY1MOuwXAu+6HR0RETjmpcqkH8CMAbSKyLdH2DwDuEJFLACiAPQDu9iRCIqIQa26NYen6duzv6sa4ygo0NUxGY603dSVOqlw2AxCLh7LWnBMRlbrm1hgWrmlDd08fACDW1Y2Fa9oAwJOkzpWiREQeWbq+fSCZJ3X39GHp+nZPzseETkTkkf1d3Xm1F4sJnYjII+MqK/JqLxYTOhGRR5oaJqOivGxQW0V5GZoaJntyPidVLkREVIDkxKcxV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+hsfR/A26p6MP0BVT2qqscS378EoFxERvsdYJqDyWGqxNdDFscY9zonJrRuBvDXmhhsTOfg+vGFqh5U1T5V7QfwqE0cRr3GInIagFsBPG13TFCvr4iUI54cV6vqmkSzsdexTbyeX8NGJXQRGS4iI5LfIz6J8G7aYesAzJS4ywB8lvzYFSDbXo2IfC0xLgkRuRTx1/xTH2Ozsg5AcrZ/FoDnLY5ZD+B6ERmZGC64PtEWCBG5AcDDerACAAABIklEQVR8ANNV9bjNMU6uH1+kzevcYhPHfwK4QEQmJj7l/QDxv01QrgWwU1X3WT0Y1Oub+P9nBYD3VHVZykNGXsd28fpyDXs521vA7PB5iM/0bwewA8D9ifa/BfC3ie8FwC8Rrw5oA1AXcMzDEE/QX01pS433nsR/y3bEJ0Km+RzfUwAOAOhBvLfyYwBnAdgIYFfi66jEsXUAHkt57p0A3k/8+5uAY34f8bHQbYl/v0ocOw7AS9mun4DiXZW4Pt9BPPGMTY838fONiFdBfBBkvIn2J5LXbcqxJry+30F8mOSdlL//jaZex1ni9fwa5kpRIqKIMGrIhYiICseETkQUEUzoREQRwYRORBQRTOhERBHBhE5EFBFM6EREEcGETkQUEf8fxbnZ9rX3Kb4AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Computing cost function\n",
    "def cost_function(m,theta0,theta1,x,y):\n",
    "    return 1/2/m* sum([(theta0 + theta1*np.asarray([x[i]])-y[i])**2 for i in range(m)])      # Here m is the number of training exaples, theta0 and theta1 are the parameters\n",
    "                                                                                                # theta0+theta1*X is our hypotheses function \n",
    "    \n",
    "#Gradient Descent Algorithm function\n",
    "def gradient_descent(alpha,x,y,precion_rate=0.0001,max_iterations=1000):\n",
    "    converged=False\n",
    "    iterations=0\n",
    "    m=x.shape[0]         #number of training samples\n",
    "    \n",
    "    #initializing theta\n",
    "    theta0=0\n",
    "    theta1=0\n",
    "    \n",
    "    #cost function J(theta) for mean squared error\n",
    "    J = cost_function(m,theta0,theta1,x,y)\n",
    "    print('J=',J)\n",
    "    \n",
    "    #Iterate loop\n",
    "    num_iterations=0\n",
    "    while not converged:\n",
    "        # for each training we will compute the gradient (d/d_theta J(theta))\n",
    "        grad0= 1.0/m*sum([(theta0 + theta1*np.asarray([x[i]])-y[i]) for i in range (m)])\n",
    "        grad1= 1.0/m*sum([(theta0 + theta1*np.asarray([x[i]])-y[i])*np.asarray([x[i]]) for i in range(m)])\n",
    "        \n",
    "        #update the temporary parameters \n",
    "        temp0= theta0 - alpha*grad0\n",
    "        temp1= theta1 - alpha*grad1\n",
    "        \n",
    "        #update actual parameters\n",
    "        theta0=temp0\n",
    "        theta1=temp1\n",
    "        \n",
    "        #mean squared error \n",
    "        e = cost_function(m,theta0,theta1,x,y)\n",
    "        print('J=',e)\n",
    "        J=e             #update error\n",
    "        iterations+=1   #update iterations\n",
    "        \n",
    "        \n",
    "        if iterations== max_iterations:\n",
    "            print(\"Maximum iterations exceeded!\")\n",
    "            converged=True\n",
    "        \n",
    "    return theta0,theta1\n",
    "    \n",
    "\n",
    "if __name__== '__main__':\n",
    "    df=pd.read_csv('file1.txt',names=['x','y'])                           #the file has been added to the repository\n",
    "    x=df['x']\n",
    "    y=df['y']\n",
    "    \n",
    "    alpha=0.01  #learning rate\n",
    "    precision_rate=0.01     #convergence criteria \n",
    "    \n",
    "    #call gradient descent, and get the values for intercept(=theta0) and slope(=theta1) according to the equation y=m*x+c\n",
    "    theta0,theta1= gradient_descent(alpha,x,y,precision_rate,max_iterations=1000)\n",
    "    print('theta0='+str(theta0)+ 'theta1='+str(theta1))\n",
    "    \n",
    "    #plot to evaluate perfromance\n",
    "    for i in range (x.shape[0]):\n",
    "        y_predict=theta0+theta1*x\n",
    "    \n",
    "    pylab.plot(x,y,'o')\n",
    "    pylab.plot(x,y_predict,'k-')\n",
    "    pylab.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
